#!/bin/sh
#
# clean-all -- clean all docker labs
#
# Copyright (C) 2016-2020 Wu Zhangjin <lzufalcon@163.com>
#

export RELEASE=0

read -p 'This command is dangerous, are you sure? (yes/no) ' sure

[ "x$sure" != 'xyes' ] && exit 0

uname | grep -q MINGW && PWD_OPT="-W"
TOP_DIR="$(cd "$(dirname "$0")"/../../ && pwd $PWD_OPT)"
. "$TOP_DIR"/tools/docker/config $* >/dev/null

for lab in $LABS
do
  CURRENT=$lab
  unset CONTAINER_NAME
  . "$TOP_DIR/tools/docker/config" >/dev/null 2>&1

  # Ignore the containers not exists
  [ -z "$CONTAINER_NAME" ] && continue

  #docker ps -f name=$CONTAINER_NAME | grep -qv PORTS
  #[ $? -ne 0 ] && continue

  "$DOCKER_CLEAN_CMD" $lab

done

"$TOP_DIR/tools/docker/rm-all"

$DOCKER_RELEASE_CMD all >/dev/null 2>&1
